import axios from 'axios'

const mutations={
	Navlist(state){
		if(localStorage.getItem('hidNav')&&localStorage.getItem('showNav')){
			state.items=JSON.parse(localStorage.getItem('showNav'))
			state.add_items=JSON.parse(localStorage.getItem('hidNav'))
		}
	},
	//Ajax请求参数
	add(state,id){
		state.count++
		(state.items[id].a_number)++
	},
	reduce(state){
		state.count=1
	},
	//Nav点击请求数据
	_getAllNews(state,stark){
		state.bot_load='正在努力加载中......';
		if(sessionStorage.getItem(stark.name)){
			state.s_newList=JSON.parse(sessionStorage.getItem(stark.name))
		}else{
			state.s_newList=[]
			var adr=stark.a
			axios({
				method:'get',
				url:adr,
				params:{
						rid:stark.num
					}
			}).then((res)=>{
				state.s_newList=res.data.data
				sessionStorage.setItem(stark.name, JSON.stringify(res.data.data));
				//console.log(res.data.data)
			})
		}
	},
	//scroll请求数据
	_pushNews(state,obj){
		axios({
				method:'get',
				url:obj.a,
				params:{
					rid:obj.n
				}
		}).then((res)=>{
				state.s_newList=(state.s_newList).concat(res.data.data)
				sessionStorage.setItem(obj.name, JSON.stringify(state.s_newList));
			})
	},
	//记录滚动条位置
	s_topChange(state,con){
		state.items[con.index].s_top=con.top
	},
	_add(state){
		state.count++
	},
	_reduce(state){
		state.count--
	},
	//pull_loadmore
	pull_road(state,obj){
		var that = this
		var address=obj.url;
		setTimeout(function() {
			axios({
				method:'get',
				url:address,
				params:{
						rid:1
					}
			}).then((res)=>{
				var load_arr=res.data.data;
				var Ran=[];
				var Ram=[];//随机数数组
				for(var i=0;i<load_arr.length;i++){
					Ran.push(i)
				}
				for(var num,i=0;i<5;i++){
					
					do{num=Math.floor(Math.random()*14)}while(Ran[num]==null);
					Ram.push(Ran[num])
					Ran[num]=null;
				}
				Ram.forEach(function(e){
					state.s_newList.unshift(load_arr[e]);
					state.load_tip=true
					setTimeout(function(){
						state.load_tip=false
						state.load_resh=false
					},1000)
				})
				
			})
		}, 1100)
	}
	
	
}

export default mutations